package com.rc.saas.tenant.controller.system;

import com.rc.saas.tenant.base.WebPageInfo;
import com.rc.saas.tenant.common.vo.TResponse;
import com.rc.saas.tenant.model.system.RcMsgNotification;
import com.rc.saas.tenant.model.tenant.TenantUser;
import com.rc.saas.tenant.service.system.RcMsgNotificationService;
import com.rc.saas.tenant.shiro.ShiroUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/sys/msg")
public class RcMsgNotificationController {

    @Autowired
    private RcMsgNotificationService msgNotificationService;

    @RequestMapping("/index")
    public String index() {
        return "/templates/system/rcMsg";
    }

    @ResponseBody
    @RequestMapping("/listMsg")
    public List listMsg() {
        TenantUser user= ShiroUtils.getSessionUser();
        List<RcMsgNotification> list = msgNotificationService.listRcMsgNotification(user.getTenantCode());
        return list;
    }
    @ResponseBody
    @RequestMapping("/readMsg")
    public TResponse readMsg(@Param("id") Long id) {
        msgNotificationService.updateMsgForRead(id);
        return TResponse.SUCCESS();
    }
    @ResponseBody
    @RequestMapping("/clear")
    public TResponse clearMsg(){
        TenantUser user= ShiroUtils.getSessionUser();
        msgNotificationService.updateMsgForClearMsg(user.getTenantCode());
        return TResponse.SUCCESS();
    }




}
